package com.kstech.ks_gaz01.data

import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter4.BaseQuickAdapter
import com.kstech.ks_gaz01.R
import com.kstech.ks_gaz01.databinding.LayoutTitleBinding

/**
 * author: lenovo
 * created on: 2023/12/19 10:34
 * description:
 */
class DebugDataTitleAdapter : BaseQuickAdapter<DebugDataBean.Parent, DebugDataTitleAdapter.VH>() {

    // 自定义ViewHolder类
    class VH(
        parent: ViewGroup,
        val binding: LayoutTitleBinding = LayoutTitleBinding.inflate(
            LayoutInflater.from(parent.context), parent, false
        ),
    ) : RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
        // 返回一个 ViewHolder

        return VH(parent)
    }

    override fun onBindViewHolder(
        holder: VH,
        position: Int,
        item: DebugDataBean.Parent?
    ) {

        if (item!!.selected) {
            holder.binding.root.setBackgroundColor(
                ContextCompat.getColor(
                    context,
                    R.color.background_titleRv_selected
                )
            )
        } else {
            holder.binding.root.setBackgroundColor(
                ContextCompat.getColor(
                    context,
                    R.color.background_titleRv
                )
            )
        }
        holder.binding.name.text = item!!.name
        holder.binding.name.setTextColor(Color.WHITE)
    }
}